package com.tycom.simpleapp.beans;

import java.io.Serializable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.tycom.simpleapp.model.Users;
import com.tycom.simpleapp.services.UserService;

@Component
@Scope (value = "view")
public class LoginBean implements Serializable {

	private static final long serialVersionUID = 5962682244562739811L;
	
	@Autowired
	UserService userService;
	
	private int count = 0;
	private String userName;
	private String displayName;
	
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getDisplayName() {
		return displayName;
	}
	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}
	
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	
	public void addUser() {
		count++;
		System.out.println("Add Users:"+userName + "," + displayName);
		Users user = new Users();
		user.setUserName(userName);
		user.setDisplayName(displayName);
		userService.save(user);
	}

	public void reset() {
		System.out.println("Reset the user data");
	}

	public String navigate() {
		System.out.println("Reset the user data");
		return "addUsers";
	}
}
